// 实存块管理内存, an arena has multiple memory chunk
// like pool allocator
#ifndef ARENA_INCLUDED
#define ARENA_INCLUDED
#include "except.h"

#define T Arena_T
typedef struct T *T;
extern const Except_T Arena_NewFailed;
extern const Except_T Arena_Failed;

/**
 * @brief create a new arena
 *
 * @return T
 */
extern T Arena_new(void);

/**
 * @brief free memory chunks in arena, then release the arena
 *
 * @param ap arena point
 */
extern void Arena_dispose(T *ap);

/**
 * @brief alloc memory in an arena
 *
 * @param arena
 * @param nbytes
 * @param file
 * @param line
 * @return void*
 */
extern void *Arena_alloc(T arena, long nbytes,
                         const char *file, int line);
extern void *Arena_calloc(T arena, long count,
                          long nbytes, const char *file, int line);

/**
 * @brief free memory chunks in arena
 *
 * @param arena
 */
extern void Arena_free(T arena);
#undef T
#endif